import { spawn } from 'child_process';

process.stdout.setEncoding('utf-8')

function run(...args) {
    const spawn_process = spawn('node', [...args]);

    spawn_process.stdout.on('data', (data) => {
        process.stdout.write(`${data}`)
    });

    spawn_process.stderr.on('data', (data) => {
        process.stdout.write(`\nerror：${data}`)
    });

    spawn_process.on('close', (code) => {
        process.stdout.write(`\nexit code：${code}\n重新启动中...\n\n`)
        setTimeout(() => {
            run(...args)
        }, 2000);
    }); 
}

run('watch.js')